
const Sequelize = require('sequelize');// 引入Sequelize模块
const db = require('../db');// 引入数据库实例

// 定义model
const artClass = db.define('artClass', {
    // 主键
    objectId: {
        type: Sequelize.STRING(20),
        allowNull: false,
        unique: true,
        primaryKey: true
    },

    name: {
        type: Sequelize.STRING(50),
        allowNull: false,
    },

    beizhu: {
        type: Sequelize.STRING(100),
        allowNull: true,
        defaultValue: 0,
    },

    orderNum: {
        type: Sequelize.INTEGER,
        defaultValue: 0,
        comment: "排序值"
    },

    isSee: {
        type: Sequelize.BOOLEAN,
        defaultValue: true,
        comment: "是否可见"
    },

    createdAt: {
        type: Sequelize.DATE,
        get() {
            const rawValue = this.getDataValue('createdAt');
            return dateFormat(rawValue, 'yyyy-mm-dd HH:MM:ss');
        }
    },

    updatedAt: {
        type: Sequelize.DATE,
        get() {
            const rawValue = this.getDataValue('updatedAt');
            return dateFormat(rawValue, 'yyyy-mm-dd HH:MM:ss');
        }
    },
}, {
    // 是否支持驼峰
    underscored: false,
    // MySQL数据库表名
    tableName: 'artClass',
});

/*(async () => {
    await artClass.sync({
        alter: true,
    });

    console.log("artClass字段同步成功！");
})();*/


// 定义model
const artType = db.define('artType', {
    // 主键
    objectId: {
        type: Sequelize.STRING(20),
        allowNull: false,
        unique: true,
        primaryKey: true
    },

    name: {
        type: Sequelize.STRING(50),
        allowNull: false,
    },

    artTypeClassId:{
        type: Sequelize.STRING(20),
        comment: "专题分类"
    },

    desc: {
        type: Sequelize.STRING(250),
        comment: "专题描述"
    },

    isShow: {
        type: Sequelize.BOOLEAN,
        defaultValue: true,
        comment: "精品是否可见"
    },

    images: {
        type: Sequelize.JSON,
        defaultValue: [],
        comment: "专题图片"
    },

    keyWords: {
        type: Sequelize.TEXT,
        comment: "关键词（逗号分隔，用于智能匹配）"
    },

    createdAt: {
        type: Sequelize.DATE,
        get() {
            const rawValue = this.getDataValue('createdAt');
            return dateFormat(rawValue, 'yyyy-mm-dd HH:MM:ss');
        }
    },

    updatedAt: {
        type: Sequelize.DATE,
        get() {
            const rawValue = this.getDataValue('updatedAt');
            return dateFormat(rawValue, 'yyyy-mm-dd HH:MM:ss');
        }
    },
}, {
    // 是否支持驼峰
    underscored: false,
    // MySQL数据库表名s
    tableName: 'artType',
});
/*(async () => {
    await artType.sync({
        alter: true,
    });

    console.log("artType");
})();*/

// 定义model
const artTypeClass = db.define('artTypeClass', {
    // 主键
    objectId: {
        type: Sequelize.STRING(20),
        allowNull: false,
        unique: true,
        primaryKey: true
    },

    name: {
        type: Sequelize.STRING(50),
        allowNull: false,
    },

    beizhu: {
        type: Sequelize.STRING(100),
        allowNull: true,
        defaultValue: 0,
    },

    orderNum: {
        type: Sequelize.INTEGER,
        defaultValue: 0,
        comment: "排序值"
    },

    isSee: {
        type: Sequelize.BOOLEAN,
        defaultValue: true,
        comment: "是否可见"
    },

    createdAt: {
        type: Sequelize.DATE,
        get() {
            const rawValue = this.getDataValue('createdAt');
            return dateFormat(rawValue, 'yyyy-mm-dd HH:MM:ss');
        }
    },

    updatedAt: {
        type: Sequelize.DATE,
        get() {
            const rawValue = this.getDataValue('updatedAt');
            return dateFormat(rawValue, 'yyyy-mm-dd HH:MM:ss');
        }
    },
}, {
    // 是否支持驼峰
    underscored: false,
    // MySQL数据库表名
    tableName: 'artTypeClass',
});

/*(async () => {
    await artTypeClass.sync({
        alter: true,
    });

    console.log("专题分类字段同步成功！");
})();*/


module.exports = {
    artClass,
    artType,
    artTypeClass
};
